﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Twi.COMMON.WCF
{
    public class XElementEqualityComparer : IEqualityComparer<XElement>
    {
        private string[] _comparedElementNames;//需要比较的节点名称
        public XElementEqualityComparer(string[] comparedElementNames) 
        {
            _comparedElementNames = comparedElementNames; 
        }
        public XElementEqualityComparer(string comparedElementName)
        {
            _comparedElementNames = new string[]{ comparedElementName };
        }

        #region IEqualityComparer<XElement> Members

        public bool Equals(XElement x, XElement y)
        {
            foreach (string elementName in _comparedElementNames) 
            {
                if (x.Element(elementName).Value != y.Element(elementName).Value)
                {
                    return false;
                }
            }
            return true;
        }

        public int GetHashCode(XElement obj)
        {
            return 1;
        }

        #endregion
    }
}
